// import { login, logout, getInfo } from '@/api/user'
import { LoginAPI, getUserInfoAPI } from '@/api/index.js'
// import { getUserInfo } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'
import { Message } from 'element-ui'
// import { getToken, setToken, removeToken } from '@/utils/auth'

// import { resetRouter } from '@/router'

const state = {
  token: getToken() || null
}

const mutations = {
  setToken(state, payload) {
    setToken(payload.token)
    state.token = payload.token
  }
}
const actions = {
  async setToken(context, payload) {
    console.log(payload)
    const token = await LoginAPI(payload)
    console.log(token)
    Message.success('登陆成功')
    context.commit('setToken', { token })
  },
  async getUserInfo(context, payload) {
    const res = await getUserInfoAPI()
    console.log(res)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
